/*
 * Author: Jeff Liu(jebberwocky@gmail.com)
 * Date: Sep 7, 2010 11:31:36 PM
 * 
 * License: MIT
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package org.gglgeo.core;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * The Class GeoResultStatus.
 */
public class GeoResultStatus {
    @Override
	public String toString() {
		return this.key;
	}
	
	private String key;
	
	private static List<GeoResultStatus> status = new LinkedList<GeoResultStatus>();
	
	public GeoResultStatus(String key){
		this.key = key;
		if(!status.contains(key))
			status.add(this);
	}
	
	public static GeoResultStatus get(String key){
		key = (key==null)?"":key.trim();
		Iterator<GeoResultStatus> itr = status.iterator();
		while(itr.hasNext()){
			GeoResultStatus g = itr.next();
			if(g.key.equals(key))
				return g;
		}
		return GeoResultStatus.UNKNOWN;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((key == null) ? 0 : key.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GeoResultStatus other = (GeoResultStatus) obj;
		if (key == null) {
			if (other.key != null)
				return false;
		} else if (!key.equals(other.key))
			return false;
		return true;
	}
	
	public static GeoResultStatus OK = new GeoResultStatus("OK");
    public static GeoResultStatus ZERO_RESULTS = new GeoResultStatus("ZERO_RESULTS");
    public static GeoResultStatus OVER_QUERY_LIMIT = new GeoResultStatus("OVER_QUERY_LIMIT");
    public static GeoResultStatus REQUEST_DENIED = new GeoResultStatus("REQUEST_DENIED");
    public static GeoResultStatus INVALID_REQUEST = new GeoResultStatus("INVALID_REQUEST");
    public static GeoResultStatus UNKNOWN = new GeoResultStatus("UNKNOWN");
}
